package com.ylbh.modules.feedback.controller;

import java.util.Arrays;
import java.util.Date;
import java.util.Map;

import com.ylbh.common.annotation.SysLog;
import com.ylbh.common.pojo.feedback.dto.FeedbackDTO;
import com.ylbh.common.utils.CommonResult;
import com.ylbh.common.utils.Ref;
import com.ylbh.modules.feedback.entity.ShoppingFeedback;
import com.ylbh.modules.feedback.service.ShoppingFeedbackService;
import org.apache.commons.lang.StringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.ylbh.common.utils.PageUtils;
import com.ylbh.common.utils.R;



/**
 *
 * 反馈
 * @author czx
 * @date 2019-10-07 14:40:20
 */
@RestController
@RequestMapping("feedback")
public class ShoppingFeedbackController {
    @Autowired
    private ShoppingFeedbackService shoppingFeedbackService;

    /**
     * 列表
     */
    @GetMapping("/queryFeedbackList")
    @RequiresPermissions("feedback:queryFeedbackList")
    public CommonResult queryFeedbackList(FeedbackDTO feedbackDTO){
        PageUtils page = shoppingFeedbackService.queryFeedbackList(feedbackDTO);
        return Ref.ok(page);
    }


    /**
     * 信息
     */
    @GetMapping("/getFeedbackInfoById/{backId}")
    @RequiresPermissions("feedback:getFeedbackInfoById")
    public CommonResult info(@PathVariable("backId") String backId){
		ShoppingFeedback shoppingFeedback = shoppingFeedbackService.getById(backId);
        return Ref.ok(shoppingFeedback);
    }

    /**
     * 保存
     */
//    @RequestMapping("/save")
//    @RequiresPermissions("feedback:save")
//    public R save(@RequestBody ShoppingFeedback shoppingFeedback){
//		shoppingFeedbackService.save(shoppingFeedback);
//        return R.ok();
//    }

    /**
     * 修改
     */
    @SysLog("修改反馈信息")
    @PostMapping("/modifyFeedbackById")
    @RequiresPermissions("feedback:modifyFeedbackById")
    public CommonResult modifyFeedbackById(@RequestBody ShoppingFeedback shoppingFeedback){
        if (!StringUtils.isEmpty(shoppingFeedback.getReplyContent())) {
            shoppingFeedback.setBackState("1");
            shoppingFeedback.setReplyTime(new Date());
        }
		shoppingFeedbackService.updateById(shoppingFeedback);
        return Ref.ok();
    }

    /**
     * 删除
     */
    @SysLog("删除反馈")
    @PostMapping("/removeFeedbackById")
    @RequiresPermissions("feedback:removeFeedbackById")
    public R delete(@RequestBody String[] backIds){
		shoppingFeedbackService.removeByIds(Arrays.asList(backIds));
        return R.ok();
    }

}
